package com.spa.application.service.admin;

import com.google.common.collect.Lists;
import com.spa.application.command.admin.MassageServiceAddCommand;
import com.spa.application.command.admin.MassageServiceEditCommand;
import com.spa.application.command.admin.OnOffCommand;
import com.spa.application.dto.PageResult;
import com.spa.application.dto.admin.MassageListExportDTO;
import com.spa.application.dto.admin.MassageServiceDTO;
import com.spa.application.dto.admin.MassageServiceListDTO;
import com.spa.application.dto.shop.ShopServiceDTO;
import com.spa.application.query.admin.MassageServiceQuery;
import com.spa.domain.entity.MassageServiceEntity;
import com.spa.domain.service.MassageService;
import com.spa.infrastructure.enums.dict.base.WhetherTypeEnum;
import com.spa.infrastructure.mapper.MassageServiceFlowMapperStruct;
import com.spa.infrastructure.mapper.MassageServiceMapperStruct;
import com.spa.infrastructure.repository.condition.MassageServiceCondition;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class MassageServiceApplicationService {

    @Autowired
    private MassageService massageService;

    public void addMassageService(MassageServiceAddCommand command) {
        massageService.addMassageService(command);
    }

    public PageResult<MassageServiceListDTO> page(MassageServiceQuery query) {
        return MassageServiceMapperStruct.INSTANCE.entity2MassageServiceListDto4Page(massageService.page4Admin(query));
    }

    public void onOff(OnOffCommand command) {
        massageService.switchStatus(command.getId());
    }

    public void edit(MassageServiceEditCommand command) {
        massageService.updateMassageService(command);
    }

    public MassageServiceDTO detail(MassageServiceQuery query) {
        MassageServiceEntity entity = massageService.getMassageServiceEntityById(query.getId());
        MassageServiceDTO massageServiceDTO = MassageServiceMapperStruct.INSTANCE.entity2MassageServiceDto(entity);
        massageServiceDTO.setHighlightsTarList(Lists.newArrayList(entity.getHighlightsTar().split(",")));
        massageServiceDTO.setNoteList(Lists.newArrayList(entity.getNote().split("\\|")));
        massageServiceDTO.setDeclarationList(Lists.newArrayList(entity.getDeclaration().split("\\|")));
        massageServiceDTO.setFlowList(MassageServiceFlowMapperStruct.INSTANCE.entity2Flow(entity.getMassageServiceFlowList()));
        massageServiceDTO.setImgList(Lists.newArrayList(entity.getImg().split(",")));
        return massageServiceDTO;
    }

    public List<ShopServiceDTO> serviceList() {
        MassageServiceCondition condition = new MassageServiceCondition();
        condition.setIsDel(WhetherTypeEnum.$0.getCode());
        return MassageServiceMapperStruct.INSTANCE.entity2ShopDto4List(massageService.list(condition));
    }

    public List<MassageListExportDTO> getMassageServiceList(MassageServiceQuery query) {
        return MassageServiceMapperStruct.INSTANCE.entity2MassageListExportDTO(massageService.getMassageList(query));
    }
}
